<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="企业名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入企业名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所属产业集群" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cid">
              <j-search-select-tag
                placeholder="请选择企业名称"
                v-model="model.cid"
                :dict="companyNameDict"
                :pageSize="10"
                :async="true">
              </j-search-select-tag>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="企业介绍" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="content">
              <!--<j-editor v-model="model.content" />-->
              <a-textarea v-model="model.content" rows="8" placeholder="请输入企业介绍"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="纬度" :labelCol="twoLabelCol" :wrapperCol="twoWrapperCol" prop="latitude">
              <a-input v-model="model.latitude" placeholder="请输入纬度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="经度" :labelCol="twoLabelCol" :wrapperCol="twoWrapperCol" prop="longitude">
              <a-input v-model="model.longitude" placeholder="请输入经度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="培育标签" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tag">
              <j-multi-select-tag type="list_multi" v-model="model.tag" dictCode="ind_tag,name,id" placeholder="请选择培育标签" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24" v-if="model.tagId=='1891765620924600321'">
            <a-form-model-item label="专利名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zlmc">
              <a-input placeholder="请输入" v-model="model.zlmc" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24" v-if="model.tagId=='1891766039834906625'">
            <a-form-model-item label="标准名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zlmc">
              <a-input placeholder="请输入标准名称" v-model="model.zlmc" />
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="营业收入万元" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yysr">
              <a-input v-model="model.yysr" placeholder="请输入营业收入万元"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="上缴税金" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sjsj">
              <a-input v-model="model.sjsj" placeholder="请输入上缴税金"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="从业人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cyrs">
              <a-input v-model="model.cyrs" placeholder="请输入从业人数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="img">
              <j-image-upload v-model="model.img"></j-image-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'IndCompanyForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 4 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 20 },
        },
        twoLabelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        twoWrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/indust/indCompany/add",
          edit: "/indust/indCompany/edit",
          queryById: "/indust/indCompany/queryById"
        },
        companyNameDict:'ind_cluster,name,id',
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>